package com.atguigu.spzx.cloud.user.controller;

import com.atguigu.spzx.cloud.user.entity.User;
import com.atguigu.spzx.cloud.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    UserService userService;

    @Value("${server.port}")
    String port;

    /**
     * 根据用户主键查询用户详情
     * @param userId 用户主键
     * @return 用户实体对象
     */
    @GetMapping("/findUserByUserId/{id}")
    public User findUserByUserId(@PathVariable Long id) {
        System.out.println("UserController - findUserByUserId id = " + id);
        /*try {
            Thread.sleep(61000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/
        User user = userService.findUserByUserId(id);
        user.setAddress(user.getAddress()+"-"+port);
        return user;
    }
}
